﻿define('data/tasks', ['data', 'loc'], function (data, loc) {

    var NewTask = function (fromServer) {
        fromServer = fromServer || {};
        $.extend(this, fromServer);
        this.Id = fromServer.Id || 0;
        this.Summary = ko.observable(fromServer.Summary).extend({ required: true });
        this.Description = ko.observable(fromServer.Description);
        this.ProjectId = ko.observable(fromServer.ProjectId).extend({ required: true });
        this.AssignedId = ko.observable(fromServer.AssignedId);
        var dueDate = moment(fromServer.DueDate);
        this.DueDate = ko.observable(dueDate ? dueDate.format('MM/DD/YYYY') : '');
    };

    var ListTask = function(fromServer) {
        $.extend(this, fromServer);
        var dueDate = moment(fromServer.DueDate);
        this.DueDate = ko.observable(dueDate ? dueDate.format('MM/DD/YYYY') : '');
        var updateDate = moment(fromServer.UpdateDate);
        this.UpdateDate = ko.observable(updateDate ? updateDate.format('MM/DD/YYYY') : '');
    };
    
    function list(callback, context) {
        data.get('tasks/list', callback, context);
    }

    return $.extend(new data.Crud('tasks'), {
        NewTask: NewTask,
        ListTask: ListTask,
        list: list
    });
});